package b3.widget.home.operation
{
	import b3.config.*;
	import b3.model.*;
	import b3.net.*;
	import b3.scene.home.HomeScene;
	import b3.scene.home.grid.*;
	import b3.widget.*;
	import b3.widget.basic.*;
	
	import flash.events.MouseEvent;
	
	public class OperationAttack extends BasicIcon
	{
		private var buildingModel:BuildingModel;
		
		public function OperationAttack(buildingModel:BuildingModel)
		{
			this.buildingModel = buildingModel;
			var IconBgr:Class = ResourceHelper.getInstance().getClassByName("OperationAttack");
			super(IconBgr, "占领", 1, true);
			disableMouseOverTip();
			addEventListener(MouseEvent.CLICK, onMouseClick);
			this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}
		
		private function onMouseOver(event:MouseEvent):void
		{
			HomeScene.getInstance().centerInfoPane.showOperationTip("OperationAttack", "占领建筑成为房东", 0x00AAFF);
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			HomeScene.getInstance().centerInfoPane.clear();
		}
		
		private function onMouseClick(event:MouseEvent):void
		{
			var weaponFlag:Boolean = false; 
			//检查是否有可用的导弹
			var buildings:Object = PlayerManager.getInstance().me.townModel.buildings;
			for (var i:String in buildings)
			{
				var rocket:BuildingModel = buildings[i];
				var buildingConfig:BuildingConfig = Config.buildingConfigs[rocket.buildingIndex];
				//如果导弹没有封顶 无法使用
				if (buildingConfig.type == BuildingConfig.WEAPON && rocket.roofType != -1)
				{
					weaponFlag = true;
					break;
				}
			}
			if (weaponFlag)
			{
				var weaponSelectPane:WeaponSelectPane = new WeaponSelectPane(this.buildingModel);
				weaponSelectPane.x = -weaponSelectPane.width / 2;
				weaponSelectPane.y = -weaponSelectPane.height / 2;
				WidgetManager.getInstance().popOut([weaponSelectPane], true);
			}
			else
			{
				var popMessage:PopMessage = new PopMessage("没有带弹头的导弹，请先回家建设导弹！", 0xFF0000);
				WidgetManager.getInstance().popOut([popMessage]);
			}
		}
	}
}